package LeetCode;

public class Code152_maxProduct {

    public int maxProduct(int[] nums) {
        int[] max_dp = new int[nums.length];
        int[] min_dp = new int[nums.length];
        max_dp[0] = nums[0];
        min_dp[0] = nums[0];
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            max_dp[i] = Math.max(max_dp[i-1] * nums[i],
                    Math.max(nums[i], min_dp[i-1] * nums[i]));
            min_dp[i] = Math.min(max_dp[i-1] * nums[i],
                    Math.min(nums[i], min_dp[i-1] * nums[i]));
            res = Math.max(res, max_dp[i]);
        }
        return res;
    }
}
